#include<stdio.h>
#include<math.h>

int isprime(int num)
{ 	    
    int i=0;
    if(num==1)
    return 0;
	for(i=2;i<=sqrt((double)num);i++)//1
		if(num%i==0)
			return 0;
	return 1;
} 	    
int main()
{ 	    
	int N,flag=0;
	scanf("%d",&N);
	if(N>=1&&N<=10)
	while(N--)//1
	{ 	    
		int num,i,j;
		scanf("%d",&num);
		if(num<=100&&num>=1){ 	    
		    flag=1;
		if(num==1)
		{ 	    
		    printf("2 1\n");
			continue;
		}
		for(i=num;!isprime(i);i--);//1
		for(j=num;!isprime(j);j++);//1
		}
        if(flag){ 	    
		if((num-i)<(j-num))//1
		printf("%d %d\n",i,num-i);
		else if((num-i)>(j-num))//1
		printf("%d %d\n",j,j-num);
		else if((num-i)==(j-num))//1
		printf("%d %d\n",i,num-i);
        }
	}
	if(!flag)
	printf("Input error!\n");
	return 0;
}